package cn.yh.springbootjwt.controller;

import cn.yh.springbootjwt.common.AjaxResult;
import cn.yh.springbootjwt.controller.base.BaseController;
import cn.yh.springbootjwt.domain.vo.CollectListVo;
import cn.yh.springbootjwt.service.ICollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/collect")
@Api(tags = "收藏管理接口")
public class CollectController extends BaseController {
    @Autowired
    private ICollectService collectService;

    @ApiOperation( value = "用户添加/取消收藏", notes = "当前商品是未收藏状态则变为收藏状态；当商品是已收藏状态则取消收藏。" )
    @PostMapping("/{productId}")
    public AjaxResult isCollect(@PathVariable Long productId){
        return toAjax(collectService.isCollect(productId));
    }


    @ApiOperation( value = "用户查询当前收藏", notes = "获取当前用户收藏的商品列表。" )
    @GetMapping("/list")
    @ApiImplicitParam(name = "token", paramType = "header", required = true)
    public AjaxResult<CollectListVo> getCollectList(){
        return AjaxResult.success(collectService.getCollectList());
    }
}


